const app = getApp()
var httpClient = require("../../../utils/HttpClient.js");
var commonUtil = require("../../../utils/CommonUtil.js");

Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    userInfo: {},
    detail: {},
    evevator: {},
    ProblemInfo:'',
    submiting: ''
  },
  changeInput(e) {
    let changed = {};
    let prop = e.currentTarget.dataset.prop
    changed[prop] = e.detail.value;
    this.setData(changed)
  },
  onLoad: function(option) {
    this.setData({
      userInfo: app.globalData.userInfo,
      nowTime: commonUtil.formatTime(new Date())
    });
  },
  PickerChange(e) {
    this.setData({
      personIndex: e.detail.value
    })
  },
  submitClick: function(e) {
    if (this.data.evevator.ElevatorNumber && this.data.ProblemInfo){
      this.setData({
        submiting: "submiting"
      });
      var RepairReportInfo = {
        "CustomerName": this.data.userInfo.mp.CompanyName,
        "CustomerNumber": this.data.userInfo.mp.CustomerNumber,
        "ElevatorNumber": this.data.evevator.ElevatorNumber,
        "EmployeeNumber": this.data.userInfo.mp.EmployeeNumber,
        "ProblemInfo": this.data.ProblemInfo,
        "RepairsName": this.data.userInfo.mp.EmployeeName,
        "RepairsTel": this.data.userInfo.mp.MobilePhone,
        "RepairsTime": this.data.nowTime
      };


      httpClient.superAjax({
        isWebService: true,
        showWarnAlert: true,
        operateType: '提交',
        url: 'CustomerService.asmx/AddRepairReportMin',
        data: {
          repairData: JSON.stringify(RepairReportInfo),
          flg: 1, //2 困人，1报修
          _this: this
        },
        success: function (data) {
          var result = '操作失败';
          if (data.length > 0 && data[0].Code == 200) {
            result = '操作成功';
          }
          wx.showToast({
            icon: 'none',
            title: result,
            duration: 4000,
            success: function () {
              wx.navigateBack({
                delta: 1
              })
            }
          })
        },
        complete: function () {
          this.data._this.setData({
            submiting: ""
          });
        },
        warnAlertCancelCall: function () {
          this.data._this.setData({
            submiting: ""
          });
        }
      })

    } else if (!this.data.evevator.ElevatorNumber){
      wx.showToast({
        icon: 'none',
        title: '未选择电梯',
      })
    }else{
      wx.showToast({
        icon: 'none',
        title: '故障描述不能为空',
      })
    }




  },
})